import request from '@/utils/request'
import type { ResponseData } from '@/types/common'
import type { Booking, BookingQuery } from '@/types/booking'

// 创建预约
export const createBooking = (data: {
  package_id: number
  photographer_id: number
  shooting_date: string
  customer_name: string
  customer_phone: string
  customer_email: string
  wedding_date: string
  remark?: string
}) => {
  return request.post<ResponseData>('/bookings', data)
}

// 获取预约列表
export const getBookings = (params?: {
  keyword?: string
  status?: number
  startTime?: string
  endTime?: string
  page?: number
  pageSize?: number
  photographerId?: number  // 新增摄影师ID参数
}) => {
  return request.get<{
    code: number
    data: {
      items: Booking[]
      meta: {
        total: number
        page: number
        pageSize: number
        totalPage: number
      }
    }
    message: string
  }>('/bookings/list', {
    params: {
      keyword: params?.keyword || '',
      status: params?.status,
      start_date: params?.startTime,
      end_date: params?.endTime,
      page: params?.page || 1,
      pageSize: params?.pageSize || 10,
      photographer_id: params?.photographerId  // 添加摄影师ID参数传递
    },
  })
}

// 获取预约详情
export const getBookingDetail = (id: number) => {
  return request.get<{
    code: number
    data: Booking
    message: string
  }>(`/bookings/${id}/detail`)
}

// 确认预约
export const confirmBooking = (id: number) => {
  return request.patch<ResponseData>(`/bookings/${id}/confirm`)
}

// 取消预约
export const cancelBooking = (id: number, reason?: string) => {
  return request.patch<ResponseData>(`/bookings/${id}/cancel`, { reason })
}
